// Zepto
var $ = require('./components/zepto/zepto');
require('./components/zepto/event');
require('./components/zepto/ajax');
require('./components/zepto/form');
require('./components/zepto/ie');
require('./components/zepto/touch');

module.exports = $;

// 引入Swiper

var Swiper = require('./components/swiper/swiper.min.js');
var swiperAnimate = require('./components/swiper/swiper.animate1.0.2.min.js');
var swiper = new Swiper ('.swiper-container', {
  onInit: function(swiper){ //Swiper2.x的初始化是onFirstInit
    swiperAnimate.swiperAnimateCache(swiper); //隐藏动画元素 
    swiperAnimate.swiperAnimate(swiper); //初始化完成开始动画
  }, 
  onSlideChangeEnd: function(swiper){ 
    swiperAnimate.swiperAnimate(swiper); //每个slide切换结束时也运行当前slide动画
  } 
}) 

var IScroll = require('./components/iscroll/iscroll');
function loaded () {
    myScroll = new IScroll('#wrapper', { bounceEasing: 'elastic', bounceTime: 1200 });
}
 $("#mainContainer").hide();
 $(".swiper-container").hide();
// jquery/zepto
$("#enter").tap(function(){
    $(".swiper-container").hide();
    $("#mainContainer").show();

    $.ajax({
        type:'GET',
        url:'http://localhost:8000/api/skill.php',
        dataType:'json',
        success:function(data){
            var html = "";
            for(var i=0;i<data.length;i++){
                html +="<li>"
                html+='<div class="left"><p>'+data[i].category+'</p></div>';
                html+='<div class="right">';
                html+='<div class="r-top">'+data[i].name+'</div>';
                html+='<div class="r-bot">水平：'+data[i].level+'</div>';
                html+='</div>';
                html+="</li>";
            }
            $("#scroller ul").html(html);
            loaded();
        }
    })


        
})

$("#footer div").tap(function(){
    var apiTarget = $(this).attr('id');
    var apiUrl = "http://localhost:8000/api/" + apiTarget + ".php";
    $.ajax({
        type:'GET',
        url:apiUrl,
        success:function(data){
            var html = "";
                for(var i=0;i<data.length;i++){
                    html +="<li>"
                    html+='<div class="left"><p>'+data[i].category+'</p></div>';
                    html+='<div class="right">';
                    html+='<div class="r-top">'+data[i].name+'</div>';
                    if(data[i].level){
                         html+='<div class="r-bot">水平：'+data[i].level+'</div>';
                    }else if(data[i].description){
                        html+='<div class="r-bot">项目描述：'+data[i].description+'</div>';
                        html+='<div class="r-bot">大致内容：'+data[i].detail+'</div>';
                         html+='<div class="r-bot">应用到的技术：'+data[i].tech+'</div>';
                    }else if(data[i].time){
                        html+='<div class="r-bot">担任职务：'+data[i].reportto+'</div>';
                        html+='<div class="r-bot">任职时间：'+data[i].time+'</div>';
                         html+='<div class="r-bot">主要项目：'+data[i].projects+'</div>';
                    }                  
                    html+='</div>';
                    html+="</li>";
                }
            $("#scroller ul").html(html);
            loaded ();
        }
    })

})



var interval  = setInterval(function(){
    if(document.readyState === 'complete'){
        clearInterval(interval);
        $("#loading").hide();
        $(".swiper-container").show();
        swiper.updateContainerSize(); // 万分重要
        swiper.updateSlidesSize(); // 万分重要
    }else{
        $("#loading").show();
    }
})
